package com.yq.homework.day18;


/**
 * @author 3307235355@qq.com
 * @since 2022/06/18 14:06
 *
 * 定义一个接口Compute，用来完成计算器的功能，给出四个抽象方法：加减乘除。
 * 然后请用以下三种方式测试：
 *    1，编写实现类进行测试
 *    2，用局部内部类进行测试
 *    3，使用匿名内部类进行测试
 */
public class Demo01 {
    public static void main(String[] args) {
        // 1，编写实现类进行测试
        Calculation c1 = new Calculation();
        System.out.println(c1.sum(10, 20));
        System.out.println(c1.subtraction(20, 2));
        System.out.println(c1.multiplication(25, 45));
        System.out.println(c1.division(25, 5));
        System.out.println("=======================");

        // 2，用局部内部类进行测试
        calculation();
        System.out.println("=======================");


        // 3，使用匿名内部类进行测试
        Compute c2=new Compute(){
            @Override
            public int sum(int a, int b) {
                return a+b;
            }

            @Override
            public int subtraction(int a, int b) {
                return a-b;
            }

            @Override
            public int multiplication(int a, int b) {
                return a*b;
            }

            @Override
            public int division(int a, int b) {
                return a/b;
            }
        };
        System.out.println(c2.sum(10, 20));
        System.out.println(c2.subtraction(20, 2));
        System.out.println(c2.multiplication(25, 45));
        System.out.println(c2.division(25, 5));

    }

    public static  void calculation(){
        //局部内部类
        class Inner implements Compute{

            @Override
            public int sum(int a, int b) {
                return a+b;
            }

            @Override
            public int subtraction(int a, int b) {
                return a-b;
            }

            @Override
            public int multiplication(int a, int b) {
                return a*b;
            }

            @Override
            public int division(int a, int b) {
                return a/b;
            }
        }
        Inner i1 = new Inner();
        System.out.println(i1.sum(10, 20));
        System.out.println(i1.subtraction(20, 2));
        System.out.println(i1.multiplication(25, 45));
        System.out.println(i1.division(25, 5));

    }

}
interface Compute{
    int sum(int a,int b);
    int subtraction(int a,int b);
    int multiplication(int a,int b);
    int division(int a,int b);
}

//1.实现类进行测试
class Calculation implements Compute{
    @Override
    public int sum(int a, int b) {
        return a+b;
    }

    @Override
    public int subtraction(int a, int b) {
        return a-b;
    }

    @Override
    public int multiplication(int a, int b) {
        return a*b;
    }

    @Override
    public int division(int a, int b) {
        return a/b;
    }
}



